/*
 * @Author: your name
 * @Date: 2021-08-24 10:19:29
 * @LastEditTime: 2021-12-03 15:43:58
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \bigdate\vite.config.js
 */
import { defineConfig, loadEnv,UserConfigExport, ConfigEnv } from 'vite';

import { createVitePlugins } from './build';
import path from 'path';

function pathResolve(dir) {

  return path.resolve(process.cwd(), '.', dir);
}
// 次函数会返回一个 command 当前运行命令，mode 运行环境
export default ({ command, mode }: ConfigEnv):UserConfigExport => {
  // 确定当前运行环境
  const modes = process.env.VITE_ENV ?? mode;
  // 确定当前运行脚本是否为build
  const isBuild = command == 'build';
  // 环境变量
  const env = loadEnv(`${modes}`, process.cwd());
 
  return defineConfig({
    // 在生产中服务时的基本公共路径
    // base 相当于 webpack的publicPath  
    base: env.VITE_ENV === 'development' ? '/' : '/Elk-Admin',
    // 指定静态资源服务的文件夹 默认也是public
    publicDir: 'public',

    plugins: createVitePlugins(env,isBuild),
    resolve: {
      alias: {
        '@': pathResolve('src') + '/',
        '@views': pathResolve('./src/views') + '/',
      }
    },
    server: {
      proxy: {
       
      }
    },
    optimizeDeps: {
     
      exclude: ['vue-demi'],
    },
    build: {
      // 代码分割
      cssCodeSplit:true,
      terserOptions: {
        //打包后移除console和注释
        compress: {
          drop_console: true,
          drop_debugger: true,
        },
      },
    //  禁止使用拆包打包,使用拆包需要node权限

    },
  
  })
}

